import {Component} from '@angular/core';
import {AuthService} from "../service/auth.service";
import {ToastOptions, ToastData, ToastyService} from "ng2-toasty";

@Component({
    moduleId: module.id,
    selector: 'my-retrieve-password',
    templateUrl: 'retrieve-password.component.html',
    styleUrls: ['retrieve-password.component.css'],
})

export class RetrievePasswordComponent{

  phone:string;

  constructor(public authService: AuthService, private toastyService:ToastyService) {};

  sendRetrievePasswordMail() {
    this.authService.sendRetrievePasswordMail(this.phone).subscribe( isSend => {
      let toastOptions:ToastOptions;
      if (isSend) {
        toastOptions = {
          title: "提示信息",
          msg: "发送邮件成功！",
          showClose: true,
          timeout: 1200,
          theme: 'bootstrap',
          onAdd: (toast:ToastData) => {},
          onRemove: (toast:ToastData) => {}
        };
      } else {
        toastOptions = {
          title: "提示信息",
          msg: "发送邮件失败！无此账户！",
          showClose: true,
          timeout: 1200,
          theme: 'bootstrap',
          onAdd: (toast:ToastData) => {},
          onRemove: (toast:ToastData) => {}
        };
      }
      this.toastyService.success(toastOptions);
    });
  }



}
